package com.weiyi.mashangzhu.Landlord.Activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Activity.AboutActivity;
import com.weiyi.mashangzhu.Utils.GlideImgManager;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RulesActivity extends AppCompatActivity {

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.qustion)
    TextView qustion;
    @BindView(R.id.content)
    TextView content;
    String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rules);
        ButterKnife.bind(this);
        String s=getIntent().getStringExtra("title");
        title.setText(s);
        if (s.equals("管理规范")){
            url= API.Standard_Api;
            initStandard();
        }else {
            url= API.Resp_Api;
            initResp();
        }


        
        
        
        

    }

    private void initStandard() {
        LoadingDialog.show(RulesActivity.this);
        OkHttpUtils.get().
                addParams("token", SPUtils.get(this, "token", "") + "")
                .url(API.BaseApi_L + url).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                LoadingDialog.dismiss(RulesActivity.this);
                T.showShort(RulesActivity.this, "网络连接失败，请检查一下网络设置");
            }

            @Override
            public void onResponse(String response) {
                Log.e("fffffff","=="+response);
                LoadingDialog.dismiss(RulesActivity.this);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt("status")==0){
                    JSONObject jsonArray = jsonObject.getJSONObject("data");
                    qustion.setText("1、"+jsonArray.getString("standTitle") + "");
                    content.setText(jsonArray.getString("standContent") + "");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });


    }

    private void initResp() {
        OkHttpUtils.post().
                addParams("token", SPUtils.get(this, "token", "") + "")
                .url(API.BaseApi_L + url).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                T.showShort(RulesActivity.this, "网络连接失败，请检查一下网络设置");
            }

            @Override
            public void onResponse(String response) {
                Log.e("fffffff","=="+response);
                LoadingDialog.dismiss(RulesActivity.this);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt("status")==0){
                        JSONObject jsonArray = jsonObject.getJSONObject("data");
                        qustion.setText("1、"+jsonArray.getString("respTitle") + "");
                        content.setText(jsonArray.getString("respContent") + "");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });

    }

    @OnClick(R.id.back)
    public void onClick() {
        finish();
    }
}
